package com.qf.controller;

import com.qf.config.AliyunProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lixu
 */
@RestController
@RequestMapping("/aliyun")
public class AliyunController {

    /**
     * 第一种：加载application.yml 中外部资源信息
     */
    @Value("${aliyun.ip}")
    private String aliyunId;
    @Value("${aliyun.username}")
    private String aliyunUsername;

    /**
     * 第二种： 加载application.yml 中外部资源信息
     */
    @Autowired
    private Environment environment;//环境接口
    @GetMapping("/info")
    public String info(){
        String ip = environment.getProperty("aliyun.ip");
        String username = environment.getProperty("aliyun.username");
        String endpoint = environment.getProperty("aliyun.endpoint");
        return "OK";
    }

    /**
     * 第三种： 加载application.yml 中外部资源信息
     */
    @Autowired
    private AliyunProperties aliyunProperties;
    @GetMapping("/info3")
    public String info3(){
        System.out.println(aliyunProperties.getIp() + ":" + aliyunProperties.getUsername() +
                ":" + aliyunProperties.getEndpoint());
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();

        return "OK";
    }


}
